   <!DOCTYPE html>
<html>
<head>
<head />
<div th:include="base-libs :: base-libs" />
<title>保存签约申请</title>
<style type="text/css">
.topBtn{
	float: right;
	margin-right:10px;
	margin-top:5px
}
</style>
</head>
<script th:inline="javascript">
	/**发起机构信息*/
	var fqyljgxx = [[${fqyljgxx}]];
	/**签约申请医联体信息*/
	var qysqxx = [[${qysqxx}]];
	/**签约机构信息*/
	var qyjgxx = [[${qyjgxx}]];
</script>
<script type="text/javascript">
	$(function() {
		$(this).registerManagerPage({callback: initData});
		initView();
		//initData(); 
	});

	function initData() {
		/**加载发起机构信息*/
		initFqjg();
		/**加载医联体信息*/
		initQysqxx();
		/**加载签约机构信息*/
		initQyjgxx();
		$("#managerForm").attr("action", "save");
		
	}

	function initView() {
		$(".yltxx").each(function(){
			$(this).attr("disabled","disabled");
		});
		fqyljgxx[0]["KSDM"] = "";
		fqyljgxx[0]["KSMC"] = "";
		$("#ksTr").find(".ksxx").hide();
		$("#ksTr").find(".yydz").attr("colspan","5");
		$("#ksTr").find(".yydz input").css("width","97.5%");
		
		/**根据医联体类型改变option*/
		$("#YLTLX").on("change", function(){
			if($(this).val() == "03"){
				$("#ksTr").find(".ksxx").show();
				$("#ksTr").find(".yydz").removeAttr("colspan");
				$("#ksTr").find(".yydz input").css("width","90%");
				$("#KSMC").attr("quick-config","label:'科室名称', validateProxy:'notNull'");
				$("#jgxxTable").datagrid(getOption($(this).val()));
			}else{
				$("#ksTr").find(".ksxx").hide();
				$("#ksTr").find(".yydz").attr("colspan","5");
				$("#ksTr").find(".yydz input").css("width","97.5%");
				$("#KSMC").val("");
				$("#KSMC").removeAttr("quick-config");
				$("#jgxxTable").datagrid(getOption());
			}
			$("#jgxxTable").datagrid("loadData",{total: 0, rows: []});
		});
		
		$("#jgxxTable").datagrid(getOption());
		
		
		
		
		
		/**选择医联体*/
		$("#xzYlt").on("click", function(){
			//页面层
			var cache = {};
			cache["YLTID"] = $("#YLTID").val();
			cache["YLJGID"] = $("#PTJGID").val();
			StoreCache.setCache("QYSQ_YLTXX", cache);
			parent.layer.open({
				type: 2,
		  		area: ["80%", "500px"], //宽高
		  		scrollbar: false,
		  		resize: false,
				move: false,
				title: "医联体信息列表",
				content: contextRoot + "jrylt/" +"ylt.html",
				end: function () {
					var info = StoreCache.removeCache("QYSQ_YLTXX");
					if(info){
						/**重新加载数据*/
						//fqyljgxx = info["fqyljgxx"];
						qysqxx = info["qysqxx"];
						qyjgxx = info["qyjgxx"];
						initData();
						$("#YLTLX").trigger("change");
					} 
				}
			});
		});
		
		/**选择科室*/
		$("#xzKs").on("click", function(){
			//页面层
			var cache = {};
			cache["PTJGID"] = $("#PTJGID").val();
			cache["KSDM"] = $("#KSDM").val();
			StoreCache.setCache("QYSQ_KSXX",cache);
			parent.layer.open({
				type: 2,
		  		area: ["60%", "500px"], //宽高
		  		scrollbar: false,
		  		resize: false,
				move: false,
				content: contextRoot + "jrylt/" +"kslb.html",
				end: function () {
					var info = StoreCache.removeCache("QYSQ_KSXX");
					if(info){
						fqyljgxx[0]["KSDM"] = info["KSDM"];
						fqyljgxx[0]["KSMC"] = info["KSMC"];
						$("#KSDM").val(info["KSDM"]);
						$("#KSMC").val(info["KSMC"]);
						initData();
					}
				}
			});
		});
		
		
		/**提交按钮*/
		$("#btnSave").on("click", function(){
			if($(".form-control").QuickValidate() && validateJg()){
				var params = {};
				params["QYZT"] = "02";
				submitForm(params);
			}
		});
		
		/**暂存按钮*/
		$("#btnZc").on("click", function(){
			if($(".form-control").QuickValidate() && validateJg()){
				var params = {};
				params["QYZT"] = "01";
				submitForm(params);
			}
		});
		
	}

	/**提交表单*/
	function submitForm(params){
		params["YLTLX"] = $("#YLTLX").val();
		params["YLJGID"] = $("#PTJGID").val();
		params["QYYXQ"] = $("#QYYXQ").val();
		params["QYSJ"] = $("#QYSJ").val();
		params["DQSJ"] = $("#DQSJ").val();
		if($("#YLTLX").val() == "03"){
			params["KSDMS"] = $("#KSDM").val();
		}
		params["method"] = $("#method").val();
		$.QuickRemote.AjaxFiledFormSubmit("managerForm", function(result) { 
			var info = result["info"];
			if (result["state"]) {
				$.QuickAlert.alertNormal("加入申请成功，请静待医联体主导机构接收！",{callback: function(){
					$.QuickUrlUtils.redirectUrl("index.html");
				}});
			} else {
				$.QuickAlert.alertFail({
					content : info["faultInfo"]
				});
			}
		}, params);
	}
	
	/**返回按钮*/
	function btnBackHandler() {
		$.QuickUrlUtils.redirectUrl("index.html");
	}
	
	/**加载发起机构信息*/
	function initFqjg(){
		var jgxx = fqyljgxx[0];
		$(".fqjg").find("input").each(function(){
			$(this).val(jgxx[$(this).attr("id")]);
		});
		$("#ZDYLJGID").val(jgxx["PTJGID"]);
		$("#ZDYLJGMC").val(jgxx["YLJGMC"]);
		//initJgxx();
	}
	
	/**校验医疗机构*/
	function validateJg(){
		var info = $("#jgxxTable").datagrid("getData");
		var flag = false;
		if(info["total"] == "1"){
			$.QuickAlert.alertFail({
				content : "请选择要加入的医联体！",
			});
		}else{
			flag = true;
		}
		return flag 
	}
	
	/**加载医联体信息*/
	function initQysqxx(){
		if(qysqxx){
			var info;
			$(qyjgxx).each(function(index,item){
				if(item["JGLX"]=="3"){
					info = item;
				}
			});
			info = $.extend({}, qysqxx, info);
			$(".yltxx").each(function(){
				$(this).val(info[$(this).attr("id")]);
			});
			$("#BZSM").val(qysqxx["BZSM"]);
			$("#YLTID").val(qysqxx["YLTID"]);
			if($("#YLTLX").val()=="03"){
				$("#ksTr").find(".ksxx").show();
				$("#ksTr").find(".yydz").removeAttr("colspan");
				$("#ksTr").find(".yydz input").css("width","90%");
				$("#KSMC").attr("quick-config","label:'科室名称', validateProxy:'notNull'");
			}else{
				$("#ksTr").find(".ksxx").hide();
				$("#ksTr").find(".yydz").attr("colspan","5");
				$("#ksTr").find(".yydz input").css("width","97.5%");
				$("#KSMC").val("");
				$("#KSMC").removeAttr("quick-config")
			}
		}
	}
	
	/**加载签约机构信息*/
	function initQyjgxx(){
		if(qyjgxx){
			if(qysqxx["YLTLX"] == "03"){
				$("#jgxxTable").datagrid(getOption(qysqxx["YLTLX"]));
				for ( var i in qyjgxx) {
					if(qyjgxx[i]["PTJGID"]==qysqxx["ZDYLJGID"]){
						$("#KSDM").val(qyjgxx[i]["KSDM"]);
						$("#KSMC").val(qyjgxx[i]["KSMC"]);
					}
				}
			}
			initJgxx();
			//$("#jgxxTable").datagrid("loadData",{"total": qyjgxx.length, "rows": qyjgxx});
		}
	}
	
	/**获取option*/
	function getOption(lx){
		var opt;
		if(lx == "03"){
			opt= {
					idField : "PTJGID",
					uniqueId: "PTJGID",
					striped : true,
					border:false,
					clickToSelect: true,
					fit: true,
					fitColumns: true,
					singleSelect: false,
					rownumbers: true,
					columns : [[
						{
							field : "YLJGMC",
							width: 160,
							align: "center",
							title : "机构名称"
						},
						{
							field : "XZQHMC",
							width: 100,
							align: "center",
							title : "所属区域"
						},
						{
							field : "WSJGLBMC",
							width: 120,
							align: "center",
							title : "机构类型"
						},
						{
							field : "KSMC",
							width: 200,
							align: "center",
							title : "科室",
							formatter : function(value, row, index){
								return "<span title='"+value+"'>"+value+"</span>";
							}
						},
						{
							field : "YYDJMC",
							width: 100,
							align: "center",
							title : "医院等级"
						},
						{
							field : "JGFLGLMC",
							width: 120,
							align: "center",
							title : "经营性质"
						}
					]],onLoadSuccess: function(data){
						/**假如没有数据，则默认加入当前机构*/
						if(data["total"]=="0"){
							initJgxx();
						}
						$("#jgxxLayout").layout("resize");
					}
				};
		}
		else{
			opt= {
					idField : "PTJGID",
					uniqueId: "PTJGID",
					striped : true,
					border:false,
					clickToSelect: true,
					fit: true,
					fitColumns: true,
					singleSelect: false,
					rownumbers: true,
					columns : [[
						{
							field : "YLJGMC",
							width: 250,
							align: "center",
							title : "机构名称"
						},
						{
							field : "XZQHMC",
							width: 150,
							align: "center",
							title : "所属区域"
						},
						{
							field : "WSJGLBMC",
							width: 150,
							align: "center",
							title : "机构类型"
						},
						{
							field : "YYDJMC",
							width: 150,
							align: "center",
							title : "医院等级"
						},
						{
							field : "JGFLGLMC",
							width: 150,
							align: "center",
							title : "经营性质"
						}
					]],onLoadSuccess: function(data){
						/**假如没有数据，则默认加入当前机构*/
						if(data["total"]=="0"){
							initJgxx();
						}
						$("#jgxxLayout").layout("resize");
					}
				};
		}
		return opt;
	}
	
	/**初始化选择机构table*/
	function initJgxx(){
		var ary = [];
		if(qyjgxx){
			ary = qyjgxx;
		}
		var length = 37*(ary.length);
		$("#maxDiv").css("height",length+670+"px");
		$("#maxLayout").layout("resize");
		$("#jgxxBody").css("height", length + 43+"px");
		$("#jgxxTable").datagrid("loadData",{"total": ary.length, "rows": ary});
	}
</script>

<body style="overflow-y: scroll">
<div id="maxDiv" style="height: 670px;">
	<div id="maxLayout" class="easyui-layout" fit="true">
		<div region="north" style="border: none; overflow: hidden;">
			<h4 class="h4-title" style="font-size: 18px;">
				加入医联体
			<!-- 	<button class="btn topBtn" style="float:right" type="button" onclick="btnBackHandler()">返回</button>
				<button class="btn topBtn" style="float:right" type="button" id="btnSave">提交</button>
			 --></h4>
			<div class="form-table-box" >
				<input id="method" style="display: none;" value="qysq">
				<form id="managerForm" class="form-horizontal" >
					<h4 class="h4-title" style="font-size: 13px;">
						签约申请机构
					</h4>
					<table class="form-table fqjg">
						<tr>
							<td class="td-text">
								<label>机构名称：</label>
							</td>
							<td class="td-content">
								<input id="PTJGID" style="display: none;" class="form-control dataField" type="text"
									readonly="readonly">
								<input id="YLJGMC" class="form-control dataField" type="text"
									readonly="readonly">
							</td>
							<td class="td-text">
								<label>机构编码：</label>
							</td>
							<td class="td-content">
								<input id="YLJGDM" class="form-control dataField" type="text"
									readonly="readonly">
							</td>
							<td class="td-text">
								<label>所属区域：</label>
							</td>
							<td class="td-content">
								<input id="XZQHMC" class="form-control dataField" type="text"
									readonly="readonly">
							</td>
						</tr>
						
						<tr>
							<td class="td-text">
								<label>机构类型：</label>
							</td>
							<td class="td-content">
								<input id="WSJGLBMC" class="form-control dataField" type="text"
									readonly="readonly">
							</td>
							<td class="td-text">
								<label>经营性质：</label>
							</td>
							<td class="td-content">
								<input id="JGFLGLMC" class="form-control dataField" type="text"
									readonly="readonly">
							</td>
							<td class="td-text">
								<label>医院等级：</label>
							</td>
							<td class="td-content">
								<input id="YYDJMC" class="form-control dataField" type="text"
									readonly="readonly">
							</td>
						</tr>
						<tr id="ksTr">
							<td class="td-text">
								<label>医院地址：</label>
							</td>
							<td class="td-content yydz">
								<input id="DWDZ" class="form-control dataField" type="text" 
									readonly="readonly">
							</td>
							<td class="td-text ksxx">
								<label>科室名称：</label>
							</td>
							<td class="td-content ksxx" >
								<input id="KSMC" class="form-control dataField" type="text"
								placeholder="科室名称" readonly="readonly">
								<input id="KSDM" style="display:none;">
							</td>
							<td class="td-text ksxx">
								<button class="btn" type="button"  id="xzKs">选择科室</button>
							</td>
						</tr>
					</table>
					<h4 class="h4-title" style="font-size: 13px;">
						医联体信息
					</h4>
					<table class="form-table">
						<tr>
							<td class="td-text">
								<label>医联体名称：</label>
							</td>
							<td class="td-content">
								<input id="YLTID" name="YLTID" style="display: none;"/>
								<input id="YLTMC" name="YLTMC" class="form-control dataField yltxx" type="text" style="width: 55%;"
									readonly="readonly" quick-config="label:'医联体名称', validateProxy:'notNull length', length: '50'" 
									placeholder="医联体名称">
								<!-- 按钮触发模态框 -->
								<button class="btn" type="button"  style="width: 36%;"  id="xzYlt">选择</button>
						
							</td>
							<td class="td-text">
								<label>医联体类型：</label>
							</td>
							<td class="td-content">
								<select id="YLTLX" name="YLTLX" class="form-control dataField yltxx" style="width:90%;"
								cacheTable="TB_ZY_YLTLX"	>
								</select>
							</td>
							<td class="td-text">
								<label>主导医疗机构：</label>
							</td>
							<td class="td-content">
								<!-- <select id="ZDYLJGID" class="form-control dataField" style="width:90%;">
								</select> -->
								<input id="ZDYLJGMC" readonly="readonly" class="yltxx">
								<input id="ZDYLJGID" style="display:none;">
							</td>
						</tr>
						<tr>
							<td class="td-text">
								<label>签约有效期：</label>
							</td>
							<td class="td-content">
								<select id="QYYXQ" name="QYYXQ" class="form-control dataField cacheTable yltxx" style="width:90%;"
								cacheTable="TB_ZY_YXQ" >
								</select>
							</td>
							<td class="td-text">
								<label>签约时间：</label>
							</td>
							<td class="td-content">
								<input id="QYSJ" name="QYSJ"  readonly="readonly"
								class="form-control yltxx" />
							
							</td>
							<td class="td-text">
								<label>至</label>
							</td>
							<td class="td-content">
								<input id="DQSJ" name="DQSJ" readonly="readonly"
								class="form-control dataField yltxx" quick-config="label:'到期时间', validateProxy:'notNull'" /><!-- onclick="laydate(end)" -->
							</td> 
						</tr>
					</table>
				</form>
			</div>
		</div>
		<div region="center" style="border: none;overflow: hidden;">
			<h4 class="h4-title" style="font-size: 13px;">
				添加机构
			</h4>
			<div  id="jgxxBody" style="height:43px;width:96.5%;margin-left:2.5%;">
				<div  id="jgxxLayout" class="easyui-layout" fit="true">
					<div region="center" style="border: none;">
						<table id="jgxxTable" >
									</table>
					</div>
				</div>
			</div>
			
			
			<div style="height: 320px;">
				<div class="easyui-layout" fit="true" >
					<div region="center" style="border: none">
						<div class="form-table-box" >
							<table class="form-table">
								<tr>
									<td class="td-text">
										<label>备注说明：</label>
									</td>
									<td class="td-content" colspan="5">
										<input id="BZSM" name="BZSM" class="input-text yltxx" style="width:97.5%" />
									</td>
								</tr>
							</table>
							<div class="form-table-box" >
								<h4 class="h4-title" style="font-size: 13px;">
									服务协议信息
								</h4>
								<table class="form-table">
									<tr>
										<td class="td-content">
											<input class="easyui-textbox" readonly="readonly" data-options="multiline:true" style="width:100%;height:100px">
										</td>
									</tr>
								</table>
							</div>
							<div style="text-align: center;padding-bottom:10px;">
								<button class="btn btn-primary" type="button" id="btnSave" >提交</button>
								<button class="btn btn-default" type="button" onclick="btnBackHandler()">返回</button>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script type="text/html" id="tableToolBar">
<a class="tableToolBarBtn" href="javascript:remove(#index#)" style="" title="移除" >移除</a>
</script>
</html>


